﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DepInnerTask.Common.Interface;
using Common.Service;
using System.Collections;
using DepInnerTask.Common.Entity;
using System.IO;
using IBatisNet.DataMapper;
using System.Data;

namespace Ultimus.Web
{
    public partial class DepInnerRepTask : System.Web.UI.Page
    {

        IUpLoadFile upfile = ServiceContainer.GetService<IUpLoadFile>();
        IDepInnerTask task = ServiceContainer.GetService<IDepInnerTask>();
        IDepInnerTaskReply taskrep = ServiceContainer.GetService<IDepInnerTaskReply>();
        DepInnerTaskEntity en = null;//为了判断是否工单是否关闭  在repeater中判断
        ITasks ta = ServiceContainer.GetService<ITasks>();
        private int _start = 0;
        private int _limit = 10;

        protected void Page_Load(object sender, EventArgs e)
        {
            _start = int.Parse(_StartRow.Value);
            if (!IsPostBack)
            {
                hidGuid.Value = Guid.NewGuid().ToString();//生成唯一标示
                //    Response.Write("传过来的值：" + Request.QueryString["INNER_TASK_ID"]);
                //    Response.Write("传过来的发起人值：" + Request.QueryString["StartUser"]);
                if (Request.QueryString["INNER_TASK_ID"] != "" && Request.QueryString["INNER_TASK_ID"] != null)
                {
                    hidInnerTaskID.Value = Request.QueryString["INNER_TASK_ID"].ToString();
                }

                BindInnerTask(hidInnerTaskID.Value);
                EnableTaskText();//禁用表单信息

                BindCLoseFileData();//关闭工单附件
                this.btnUpdateRep.Visible = false;//开始加载的隐藏 点击修改的时候显示
                //点击翻页的时候
                if (Request.QueryString["INNER_TASK_ID"] != "" && Request.QueryString["INNER_TASK_ID"] != null)
                {
                    en = task.Get(Request.QueryString["INNER_TASK_ID"]);//传过来的部内工单ID 
                }
                //判断只有发起人才能看到关闭工单和新增处理人  (发起人与当前登录是同一个人时才显示关闭工单和新增处理人)
                if (Session["UserName"] != null)
                {
                    if (Request.QueryString["StartUser"] == Session["UserName"].ToString())
                    {
                        this.MyTable.Visible = true;
                    }
                    else
                    {
                        this.MyTable.Visible = false;
                    }
                }
                else
                {
                    this.MyTable.Visible = false;
                }
                BindAllRep();//绑定所有回复信息
            }
        }
        #region 绑定所有回复信息
        private void BindAllRep()
        {
       
            int count = 0;
            IList list = taskrep.GetList("", _start, _limit, out count);
            if (list.Count == 0)
            {
                return;
            }
            PageDataBindding();
            this.RepList.DataSource = list;
            this.RepList.DataBind();

        }
        #endregion

        #region 绑定部内工单信息
        private void BindInnerTask(string InnerTaskID)
        {
            //首先传过一个部内工单ID
            DepInnerTaskEntity list = task.Get(InnerTaskID);
            if (list != null)
            {
                this.txtNo.Text = list.INNER_TASK_NO;
                this.txtTitile.Text = list.TITLE;
                this.txtRepUsers.Text = list.REPLY_USERS;
                this.txtCopyToUsers.Text = list.COPYTO_USERS;
                this.txtRepDate.Text = list.REQUIRE_REPLY_DATE.ToString();
                this.txtFaqi.Text = list.CREATE_BY;
                this.txtFaDate.Text = list.CREATE_DATE.ToString();
                this.txtMess.Text = list.MESSAGE_CONTENT;
                this.txtTaskDes.Text = list.TASK_DESCRIPTION;
                if (list.NOTIFY_TYPE == "2")
                {
                    this.chkEmail.Checked = true;
                }
                else if (list.NOTIFY_TYPE == "1")
                {
                    chkMess.Checked = true;//通知类型（短信）
                }
                else if (list.NOTIFY_TYPE == "3")
                {
                    chkMess.Checked = true;//通知类型（短信）
                    this.chkEmail.Checked = true;
                }
                else
                {
                    chkMess.Checked = false;//通知类型（短信）
                    this.chkEmail.Checked = false;//通知类型(没有选择)
                }
                IList lists = upfile.GetList(InnerTaskID);
                this.gvUpLoadFile.DataSource = lists;
                this.gvUpLoadFile.DataBind();
            }

        }
        #endregion

        #region 禁用通知单表信息
        private void EnableTaskText()
        {
            this.txtNo.Enabled = false;
            this.txtTitile.Enabled = false;
            this.txtRepUsers.Enabled = false;
            this.txtCopyToUsers.Enabled = false;
            this.txtRepDate.Enabled = false;
            this.txtFaqi.Enabled = false;
            this.txtFaDate.Enabled = false;
            this.txtMess.Enabled = false;
            this.txtTaskDes.Enabled = false;
            this.chkEmail.Enabled = false;
            this.chkMess.Enabled = false;
            this.file.Enabled = false;
            this.btnUpload.Enabled = false;
            this.gvUpLoadFile.Enabled = false;
            //判读是不是发起人  《关闭工单》的内容对处理人而言为灰，但允许发起人填写（发起人可见 处理人隐藏  页面加载的时候已经判读）
        }
        #endregion

        #region 工单附件Gridview
        protected void gvUpLoadFile_RowDataBound(object sender, GridViewRowEventArgs e)
        {

            //如果是绑定数据行
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                if (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate)
                {
                    ((LinkButton)e.Row.Cells[4].Controls[0]).Attributes.Add("onclick", "javascript:return confirm('你确认要删除：" + e.Row.Cells[1].Text.Trim() + "吗?')");
                }
            }
        }
        protected void gvUpLoadFile_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {

            string id = this.gvUpLoadFile.DataKeys[e.RowIndex].Value.ToString();

            //同事删除文件夹中文件
            IList list = upfile.GetList(id);
            if (list.Count > 0)
            {
                var fileName = ((UpLoadFileEntity)(list[0])).FILE_NAME;
                string pSavedPath1 = Server.MapPath("UpLoad/" + fileName);
                if (File.Exists(pSavedPath1))
                {
                    FileInfo fi = new FileInfo(pSavedPath1);
                    File.Delete(pSavedPath1);
                }
            }
            upfile.Delete(id);

        }
        #endregion

        #region 绑定工单附件
        /// <summary>
        /// 绑定GridView
        /// </summary>
        private void BindFileData()
        {
            IList list = upfile.GetList();
            this.gvUpLoadFile.DataSource = list;
            this.gvUpLoadFile.DataBind();
        }
        #endregion
        /// <summary>
        /// 点击上传附件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnUpload_Click(object sender, EventArgs e)
        {
            //判断是否上传了文件 
            if (file.HasFile)
            {
                //指定上传文件在服务器上的保存路径 
                string savePath = Server.MapPath("UpLoad/");
                //检查服务器上是否存在这个物理路径，如果不存在则创建 
                if (!System.IO.Directory.Exists(savePath))
                {
                    //需要注意的是，需要对这个物理路径有足够的权限，否则会报错 
                    //另外，这个路径应该是在网站之下，而将网站部署在C盘却把上传文件保存在D盘 
                    System.IO.Directory.CreateDirectory(savePath);
                }
                savePath = savePath + "\\" + file.FileName;
                file.SaveAs(savePath);//保存文件 
                //不过需要注意的是，在客户端访问却需要指定的是URL地址，而不是在服务器上的物理地址 
                // literal.Text = string.Format("<a href='upload/{0}'>upload/{0}</a>", file.FileName);
                //插入数据库数据
                UpLoadFileEntity fileEntity = new UpLoadFileEntity();
                fileEntity.FILE_NAME = file.FileName;
                fileEntity.FILE_SAVEPATH = file.FileName;
                fileEntity.GUID = hidGuid.Value;//来源ID
                fileEntity.IS_ACTIVE = "0";//0未激活 1已激活 2失效 
                fileEntity.PROCESS_NAME = Request.QueryString["ProcessName"];
                fileEntity.UPLOAD_BY = txtFaqi.Text.Trim();
                fileEntity.UPLOAD_DATE = DateTime.Now;
                fileEntity.UPLOAD_FILE_ID = Guid.NewGuid().ToString();//主键
                fileEntity.UPLOAD_FILE_TYPE = ""; //附件类型
                upfile.Insert(fileEntity);
                BindFileData();
            }
        }

        #region 发表回复信息
        protected void btnRep_Click(object sender, EventArgs e)
        {
            DepInnerTaskReplyEntity rep = new DepInnerTaskReplyEntity();
            // rep.ATTACHMENT_ID = "";//附件ID
            rep.CONTENT = txtrep.Text.Trim();
            if (Session["UserName"]!= null)
            {
                rep.CREATE_BY = Session["UserName"].ToString();//当前用户
            }
            else
            {
                rep.CREATE_BY = "Ultimus";//设置默认值
            }
            rep.CREATE_DATE = DateTime.Now;
            rep.INNER_TASK_ID = hidInnerTaskID.Value;//部内工单ID（传过来的值）
            rep.REPLY_DATE = DateTime.Now;
            rep.REPLY_ID = hidGuid.Value;// hidGuid.Value;//重新生成GUID
            rep.REPLY_USER_ID = hidGuid.Value;//回复人ID（传过来的值）
            rep.ATTACHMENT_ID = hidGuid.Value;
            TasksEntity taskentity = new TasksEntity();
            // taskentity.TASKID = hidGuid.Value;// hidGuid.Value;// hidGuid.Value;//重新生成GUID  注意：taskID为char(64) 而guid为char(32) 后面补齐32个空格
            taskrep.Insert(rep, taskentity);
            MessageBox("发表成功！");
            Response.Redirect(Request.RawUrl);
        }
        #endregion

        #region 回复上传附件
        protected void btnUpRep_Click(object sender, EventArgs e)
        {
            //判断是否上传了文件 
            if (FileUpload1.HasFile)
            {
                //指定上传文件在服务器上的保存路径 
                string savePath = Server.MapPath("UpLoad/");
                //检查服务器上是否存在这个物理路径，如果不存在则创建 
                if (!System.IO.Directory.Exists(savePath))
                {
                    //需要注意的是，需要对这个物理路径有足够的权限，否则会报错 
                    //另外，这个路径应该是在网站之下，而将网站部署在C盘却把上传文件保存在D盘 
                    System.IO.Directory.CreateDirectory(savePath);
                }
                savePath = savePath + "\\" + FileUpload1.FileName;
                FileUpload1.SaveAs(savePath);//保存文件 
                //不过需要注意的是，在客户端访问却需要指定的是URL地址，而不是在服务器上的物理地址 
                // literal.Text = string.Format("<a href='upload/{0}'>upload/{0}</a>", file.FileName);
                //插入数据库数据
                UpLoadFileEntity fileEntity = new UpLoadFileEntity();
                fileEntity.FILE_NAME = FileUpload1.FileName;
                fileEntity.FILE_SAVEPATH = FileUpload1.FileName;
                if (hidRepID.Value != "")//修改时用到
                {
                    fileEntity.GUID = hidRepID.Value;
                }
                else
                {
                    fileEntity.GUID = hidGuid.Value;//来源ID
                }
                fileEntity.IS_ACTIVE = "0";//0未激活 1已激活 2失效 
                fileEntity.PROCESS_NAME = Request.QueryString["ProcessName"];
                fileEntity.UPLOAD_BY = txtFaqi.Text.Trim();
                fileEntity.UPLOAD_DATE = DateTime.Now;
                fileEntity.UPLOAD_FILE_ID = Guid.NewGuid().ToString();//主键
                fileEntity.UPLOAD_FILE_TYPE = "";//附件类型
                upfile.Insert(fileEntity);
               
                if (hidRepID.Value != "")//修改时用到
                {
                    BindFileData(hidRepID.Value);
                }
                else
                {
                    BindFileData(hidGuid.Value);
                }
            }
        }
        #endregion

        #region 绑定工单附件
        /// <summary>
        /// 绑定GridView
        /// </summary>
        private void BindFileData(string guid)
        {
            IList list = upfile.GetList(guid);
            this.gvRepList.DataSource = list;
            this.gvRepList.DataBind();
        }
        #endregion

        #region 工单回复附件Gridview
        protected void gvRepList_RowDataBound(object sender, GridViewRowEventArgs e)
        {

            //如果是绑定数据行
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                if (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate)
                {
                    ((LinkButton)e.Row.Cells[4].Controls[0]).Attributes.Add("onclick", "javascript:return confirm('你确认要删除：" + e.Row.Cells[1].Text.Trim() + "吗?')");
                }
            }
        }
        protected void gvRepList_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {

            string id = this.gvRepList.DataKeys[e.RowIndex].Value.ToString();

            //同事删除文件夹中文件
            IList list = upfile.GetList(id);
            if (list.Count > 0)
            {
                var fileName = ((UpLoadFileEntity)(list[0])).FILE_NAME;
                string pSavedPath1 = Server.MapPath("UpLoad/" + fileName);
                if (File.Exists(pSavedPath1))
                {
                    FileInfo fi = new FileInfo(pSavedPath1);
                    File.Delete(pSavedPath1);
                }
            }
            upfile.Delete(id);
            Response.Redirect(Request.RawUrl);
        }
        #endregion

        #region 确定关闭工单（根据ID更新关闭相应信息）
        protected void btnClose_Click(object sender, EventArgs e)
        {
            //首先传过一个部内工单ID
            string InnerTaskID = hidInnerTaskID.Value;
            DepInnerTaskEntity taskentity = new DepInnerTaskEntity();
            taskentity.CLOSE_BY = this.txtCloseName.Text.Trim();
            taskentity.CLOSE_DATE = Convert.ToDateTime(this.txtCloseTime.Text.Trim());
            taskentity.CLOSE_DESCRIPTION = this.txtCloseDes.Text.Trim();
            taskentity.CLOSE_TYPE = "0"; //this.drpCloseType.SelectedValue;
            taskentity.INNER_TASK_ID = InnerTaskID;
            task.Update(taskentity, "1");//1代表关闭工单
            MessageBox("关闭成功！");
            Response.Redirect(Request.RawUrl);
        }
        #endregion

        #region 封装弹出信息
        private void MessageBox(string name)
        {
            Response.Write("<script type='text/javascript'>alert('" + name + "');</script>");
        }
        #endregion

        #region 确定新增处理人
        protected void btnAddUsers_Click(object sender, EventArgs e)
        {
            //首先传过一个部内工单ID
            string InnerTaskID = hidInnerTaskID.Value;
            DepInnerTaskEntity taskentity = new DepInnerTaskEntity();
            string User = "";
            if (InnerTaskID != "" && InnerTaskID != null)
            {
                taskentity = task.Get(InnerTaskID);
                User = taskentity.REPLY_USERS;

            }
            if (User != "")
            {
                taskentity.REPLY_USERS = User + "," + this.txtAddUsers.Text.Trim();
            }
            else
            {
                taskentity.REPLY_USERS = this.txtAddUsers.Text.Trim();
            }
            taskentity.INNER_TASK_ID = InnerTaskID;
            task.Update(taskentity, "2");//2代表行政处理人
            MessageBox("新增处理人成功！");
            Response.Redirect(Request.RawUrl);
        }
        #endregion

        #region 工单关闭附件Gridview
        protected void gvCloseList_RowDataBound(object sender, GridViewRowEventArgs e)
        {

            //如果是绑定数据行
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                if (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate)
                {
                    ((LinkButton)e.Row.Cells[4].Controls[0]).Attributes.Add("onclick", "javascript:return confirm('你确认要删除：" + e.Row.Cells[1].Text.Trim() + "吗?')");
                }
            }
        }
        protected void gvCloseList_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {

            string id = this.gvCloseList.DataKeys[e.RowIndex].Value.ToString();

            //同事删除文件夹中文件
            IList list = upfile.GetList(id);
            if (list.Count > 0)
            {
                var fileName = ((UpLoadFileEntity)(list[0])).FILE_NAME;
                string pSavedPath1 = Server.MapPath("UpLoad/" + fileName);
                if (File.Exists(pSavedPath1))
                {
                    FileInfo fi = new FileInfo(pSavedPath1);
                    File.Delete(pSavedPath1);
                }
            }
            upfile.Delete(id);
            Response.Redirect(Request.RawUrl);
        }
        #endregion

        /// <summary>
        /// 绑定GridView
        /// </summary>
        private void BindCLoseFileData()
        {
            IList list = upfile.GetList(hidInnerTaskID.Value);
            this.gvCloseList.DataSource = list;
            this.gvCloseList.DataBind();
        }

        #region 上传关闭附件
        protected void btnUpCloseFile_Click(object sender, EventArgs e)
        {
            //判断是否上传了文件 
            if (FileUpload2.HasFile)
            {
                //指定上传文件在服务器上的保存路径 
                string savePath = Server.MapPath("UpLoad/");
                //检查服务器上是否存在这个物理路径，如果不存在则创建 
                if (!System.IO.Directory.Exists(savePath))
                {
                    //需要注意的是，需要对这个物理路径有足够的权限，否则会报错 
                    //另外，这个路径应该是在网站之下，而将网站部署在C盘却把上传文件保存在D盘 
                    System.IO.Directory.CreateDirectory(savePath);
                }
                savePath = savePath + "\\" + FileUpload2.FileName;
                FileUpload2.SaveAs(savePath);//保存文件 
                //不过需要注意的是，在客户端访问却需要指定的是URL地址，而不是在服务器上的物理地址 
                // literal.Text = string.Format("<a href='upload/{0}'>upload/{0}</a>", file.FileName);
                //插入数据库数据
                UpLoadFileEntity fileEntity = new UpLoadFileEntity();
                fileEntity.FILE_NAME = FileUpload2.FileName;
                fileEntity.FILE_SAVEPATH = FileUpload2.FileName;
                fileEntity.GUID = hidInnerTaskID.Value;//来源ID
                fileEntity.IS_ACTIVE = "0";//0未激活 1已激活 2失效 
                fileEntity.PROCESS_NAME = Request.QueryString["ProcessName"];
                fileEntity.UPLOAD_BY = txtFaqi.Text.Trim();
                fileEntity.UPLOAD_DATE = DateTime.Now;
                fileEntity.UPLOAD_FILE_ID = Guid.NewGuid().ToString();//主键
                fileEntity.UPLOAD_FILE_TYPE = "";//附件类型
                upfile.Insert(fileEntity);
                BindCLoseFileData();
            }
        #endregion


        }
        //删除按钮的单击事件
        protected void lbtnDelComment_Click(object sender, EventArgs e)
        {
            //当前点击的按钮
            LinkButton lb = (LinkButton)sender;
            //获取传过来的CommentId
            string comId = lb.CommandArgument;
            DepInnerTaskReplyEntity rep = new DepInnerTaskReplyEntity();
            rep.CONTENT = "该回复已删除！";
            rep.REPLY_ID = comId;
            rep.REPLY_DATE = DateTime.Now;
            taskrep.UpdateByID(rep);
            Response.Redirect(Request.RawUrl);
        }
        //修改按钮的单击事件
        protected void lbtnUpComment_Click(object sender, EventArgs e)
        {
            //当前点击的按钮
            LinkButton lb = (LinkButton)sender;
            //获取传过来的CommentId
            string comId = lb.CommandArgument;
            hidRepID.Value = comId;//点击修改的时候赋值
            //修改该条评论
            BindFileData(comId);
            DepInnerTaskReplyEntity entity = taskrep.GetListByID(comId);
            this.btnUpdateRep.Visible = true;//这个时候显示
            if (entity.CONTENT.Contains("原处置意见"))
            {
                string[] arr = entity.CONTENT.Split('☆');
                hidContent.Value = arr[3];//获取原来的回复内容
                this.txtrep.Text = hidContent.Value;
            }
            else
            {
                hidContent.Value = entity.CONTENT;//获取原来的回复内容
                this.txtrep.Text = hidContent.Value;
            }
        }

        protected void lbtnFile_Click(object sender, EventArgs e)
        {
            //当前点击的按钮
            LinkButton lb = (LinkButton)sender;
            //获取传过来的CommentId
            string comId = lb.CommandArgument;
            OpenNewWinodw("MyFileList.aspx?fileid=" + comId, "我的附件", 700, 600, "", "", "yes", "no", true);

        }
        // string id = "";
        protected void RepList_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                //需要判断是否为发起人 只有发起人可以修改 删除 自己的回复信息
                ((LinkButton)e.Item.FindControl("lbtnDelComment")).Attributes.Add("onclick", "javascript:return confirm('你确认要删除吗?')");

                string ss = ((DepInnerTaskReplyEntity)(e.Item.DataItem)).CONTENT;
                Label lblContent = (Label)e.Item.FindControl("lblContent");
                LinkButton lkbtndel = (LinkButton)e.Item.FindControl("lbtnDelComment");
                LinkButton lkbtnupdate = (LinkButton)e.Item.FindControl("lbtnUpComment");
                LinkButton lkbtnFile = (LinkButton)e.Item.FindControl("lbtnFile");
                string id = lkbtnFile.CommandArgument;
                lkbtnFile.Text = GetfileName(id);
                if (ss == "该回复已删除！")
                {
                    lblContent.Text = " <font color= 'red'> " + ss + " </font> ";
                    lkbtndel.Enabled = false;
                    lkbtnupdate.Enabled = false;
                    lkbtnFile.Enabled = false;
                }
                else
                {
                    lblContent.Text = ss;
                }
                //	当该工单被关闭后（含人工关闭或系统自动终止），不再允许处理人处置意见，或删除、修改原处置意见
                if (en != null)
                {
                    lkbtndel.Enabled = false;
                    lkbtnupdate.Enabled = false;
                }
            }

        }
        #region 确定修改回复信息
        protected void btnUpdateRep_Click(object sender, EventArgs e)
        {
            if (hidRepID.Value != "")
            {
                DepInnerTaskReplyEntity rep = new DepInnerTaskReplyEntity();
                rep.ATTACHMENT_ID = "";//附件ID
                rep.CONTENT = "原处置意见：☆" + hidContent.Value + "☆修改后处置意见：☆" + txtrep.Text.Trim();
                rep.CREATE_BY = "";//当前用户
                rep.CREATE_DATE = DateTime.Now;
                rep.INNER_TASK_ID = "";//部内工单ID（传过来的值）
                rep.REPLY_DATE = DateTime.Now;
                rep.REPLY_ID = hidRepID.Value;//重新生成GUID
                rep.REPLY_USER_ID = hidGuid.Value;//回复人ID（传过来的值）
                taskrep.Update(rep);
                Response.Redirect(Request.RawUrl);
            }
            else
            {
                MessageBox("请选择要修改的信息！");
            }
        }
        #endregion

        #region 绑定附件名称（用逗号分开）
        public string GetfileName(string id)
        {
            string[] arr = id.Split(',');
            IList depreplist = null;
            for (int i = 0; i < arr.Length; i++)
            {
                depreplist = taskrep.GetList(arr[i]);
            }

            //((DepInnerTask.Common.Entity.DepInnerTaskReplyEntity)((new System.Collections.ArrayList.ArrayListDebugView(depreplist)).Items[1])).CONTENT

            string ss = "";
            if (depreplist.Count > 0)
            {
                for (int i = 0; i < depreplist.Count; i++)
                {
                    ss += ((DepInnerTaskReplyEntity)(depreplist[i])).FILE_NAME.ToString() + ",";
                }
            }
            return ss;
        }
        #endregion
        /// <summary>
        /// 当前显示数据在表格中所载行
        /// </summary>
        private void PageDataBindding()
        {
            int count = GetRepCount();
            lblPageRecord.Text = string.Format("{0}-{1}  of  {2}", _start <= 0 ? 0 : _start, (_start + 10) >= count ? count : _start + 10, count);
            this.lblCount.Text = count.ToString();
        }

        /// <summary>
        /// 获取回复数量
        /// </summary>
        /// <returns></returns>
        private int GetRepCount()
        {
            IList list = taskrep.GetList();
            return list.Count;
        }

        protected void FirstPage_Click(object sender, EventArgs e)
        {
            _start = 0;
            _StartRow.Value = "0";
            BindAllRep();
        }

        protected void UpPage_Click(object sender, EventArgs e)
        {
            if (_start > 0)
            {
                _start = int.Parse(_StartRow.Value) - _limit;
                _StartRow.Value = (int.Parse(_StartRow.Value) - _limit).ToString();
                BindAllRep();
            }
        }

        protected void DownPage_Click(object sender, EventArgs e)
        {
            _start = int.Parse(_StartRow.Value) + _limit;
            _StartRow.Value = (int.Parse(_StartRow.Value) + _limit).ToString();
            BindAllRep();
        }

        protected void LastPage_Click(object sender, EventArgs e)
        {
            int count = GetRepCount();
            int page = count / _limit;
            _start = page * _limit;
            _StartRow.Value = (page * _limit).ToString();
            _limit = count % _limit;
            BindAllRep();
        }
        #region  打开一个窗口，并且这个窗口位于最前面
        /// <summary>
        /// 打开一个窗口，并且这个窗口位于最前面
        /// </summary>
        /// <param name="Page">提用的页面</param>
        /// <param name="URL">要打开的URL</param>
        /// <param name="PageName">要打开页面的名称</param>
        /// <param name="Win_Width">窗口宽度</param>
        /// <param name="Win_Hight">窗口高度</param>
        /// <param name="Left">窗口左侧位置</param>
        /// <param name="Top">窗口右侧位置</param>
        /// <param name="CenterFlag">是否右中 yes/no</param>
        /// <param name="Status">是否显示状态栏 yes/no</param>
        /// <param name="ParentFlag">true:不关闭弹出窗口，将不能操作父窗口 false 可以操作父窗口</param>
        public void OpenNewWinodw(string URL, string PageName, int Win_Width, int Win_Hight, string Left, string Top, string CenterFlag, string Status, bool ParentFlag)
        {

            string scriptstr = "";
            if (ParentFlag)
            {
                scriptstr = "<script language=javascript>window.showModalDialog('" + URL + "','" + PageName + "','dialogWidth:" + Win_Width + "px;"
                    + "dialogHeight:" + Win_Hight + "px;dialogLeft:" + Left + "px;dialogTop:" + Top + "px;center:" + CenterFlag.ToString() + ";help:no;resizable:yes;status:" + Status + ";scroll:yes')</script>";
            }
            else
            {
                scriptstr = "<script language=javascript>window.showModelessDialog('" + URL + "','" + PageName + "','dialogWidth:" + Win_Width + "px;"
                    + "dialogHeight:" + Win_Hight + "px;dialogLeft:" + Left + "px;dialogTop:" + Top + "px;center:" + CenterFlag.ToString() + ";help:no;resizable:yes;status:" + Status + ";scroll:yes')</script>";
            }
            HttpContext.Current.Response.Write(scriptstr);
        }
        #endregion
    }
}